﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources.Core;

namespace Wimm.Common.Entities
{
    public class IncomeSource:BaseEntity
    {
        public String Name { get; protected set; }
        public Int32? IconId { get; protected set; }
        public String Description { get; protected set; }
        public int? ParentId { get; protected set; }

        public IncomeSource()
        {
            //FOR SQLighn usage only
        }

        public IncomeSource(String name, int iconid, String description, int? parentId = null, int? id = null)
        {
            this.Name        = name;
            this.Description = description;
            this.IconId      = iconid;
            this.ParentId = parentId;

            if (id.HasValue)
                this.Id = id.Value;
        }

        public override bool Equals(object obj)
        {
            IncomeSource c2 = obj as IncomeSource;
            if (c2 != null)
            {
                return this.Id == c2.Id;
            }
            return false;
        }
        public override int GetHashCode()
        {
            return this.Id.GetHashCode();
        }
    }

    public class IncomeSourceBindingModel : IncomeSource
    {
        public IncomeSourceBindingModel(IncomeSource source, Icon icon, string lang)
        {
            this.Description = source.Description;
            this.Icon        = icon;
            this.IconId      = icon.Id;
            this.Id          = source.Id;
            this.Name        = source.Name;

            ResourceContext ctx = new Windows.ApplicationModel.Resources.Core.ResourceContext();
            ctx.Languages = new string[] { lang };

            ResourceMap rmap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
            string newGreeting = string.Empty;
            try
            {
                newGreeting = rmap.GetValue((source.Description + ".Text").Replace(".", "/"), ctx).ValueAsString;
            }
            catch (Exception)
            {
                newGreeting = "??";
            }
            this.LocalDescription = newGreeting;

        }

        public string LocalDescription { get; protected set; }
        public Icon Icon { get; protected set; }
    }
}
